home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Languages / Masm V6.11 / INCLUDE / DOS.IN$ / DOS.bin
Encoding:
Text File  |  1993-08-19  |  40.3 KB  |  1,407 lines

  1. ; DOS Interface Macros - Version 1.3 - for Microsoft Macro Assembler 6.1
  2. ; (C) Copyright Microsoft Corporation, 1987, 1988, 1989, 1990, 1993
  3.  
  4. ; Typedefs for testing pointers
  5. NPVOID  TYPEDEF NEAR PTR
  6. FPVOID  TYPEDEF FAR  PTR
  7.  
  8.  
  9. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10. ;
  11. ;  For more information on the following structures refer to
  12. ;  the Microsoft MS-DOS Programmer's Reference for Version 5.0
  13. ;
  14. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15. BOOTSECTOR STRUCT 1t
  16.     bsJump          DB 3 DUP(?)
  17.     bsOemName       DB '????????'
  18.     bsBytesPerSec   DW ?
  19.     bsSecPerClust   DB ?
  20.     bsResSectors    DW ?
  21.     bsFATs          DB ?
  22.     bsRootDirEnts   DW ?
  23.     bsSectors       DW ?
  24.     bsMedia         DB ?
  25.     bsFATsecs       DW ?
  26.     bsSecPerTrack   DW ?
  27.     bsHeads         DW ?
  28.     bsHiddenSecs    DD ?
  29.     bsHugeSectors   DD ?
  30.     bsDriveNumber   DB ?
  31.     bsReserved1     DB ?
  32.     bsBootSignature DB ?
  33.     bsVolumeID      DD ?
  34.     bsVolumeLabel   DB 11 DUP(?)
  35.     bsFileSysType   DB 8 DUP(?)
  36. BOOTSECTOR ENDS
  37.  
  38. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  39. ;
  40. ;  Used with: Interrupt 21h Function 440Dh Minor Code 60h
  41. ;             Interrupt 21h Function 440Dh Minor Code 40h
  42. ;
  43. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  44. DEVICEPARAMS STRUCT 1t
  45.     dpSpecFunc      DB ?
  46.     dpDevType       DB ?
  47.     dpDevAttr       DW ?
  48.     dpCylinders     DW ?
  49.     dpMediaType     DB ?
  50.     dpBytesPerSec   DW ?
  51.     dpSecPerClust   DB ?
  52.     dpResSectors    DW ?
  53.     dpFATs          DB ?
  54.     dpRootDirEnts   DW ?
  55.     dpSectors       DW ?
  56.     dpMedia         DB ?
  57.     dpFATsecs       DW ?
  58.     dpSecPerTrack   DW ?
  59.     dpHeads         DW ?
  60.     dpHiddenSecs    DD ?
  61.     dpHugeSectors   DD ?
  62.     dpReserved1     DB 6 DUP(?) ;; A documentation error in the
  63.     dpTrkLayoutCnt  DW ?        ;; MS-DOS Programmer's Reference 5.0
  64. DEVICEPARAMS ENDS               ;; omits these last two fields.
  65.  
  66. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  67. ;
  68. ;  Used with: Interrupt 21h Function 11h
  69. ;             Interrupt 21h Function 12h
  70. ;
  71. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  72. DIRENTRY STRUCT 1t
  73.     deName          DB '????????'
  74.     deExtension     DB '???'
  75.     deAttributes    DB ?
  76.     deReserved1     DB 10 DUP(?)
  77.     deTime          DW ?
  78.     deDate          DW ?
  79.     deStartCluster  DW ?
  80.     deFileSize      DD ?
  81. DIRENTRY ENDS
  82.  
  83. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  84. ;
  85. ;  Used with: Interrupt 25h
  86. ;             Interrupt 26h
  87. ;
  88. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  89. DISKIO STRUCT 1t
  90.     diStartSector   DD ?
  91.     diSectors       DW ?
  92.     diBuffer        DD ?
  93. DISKIO ENDS
  94.  
  95. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  96. ;
  97. ;  Used with: Interrupt 21h Function 1Fh
  98. ;             Interrupt 21h Function 32h
  99. ;
  100. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  101. DPB STRUCT 1t
  102.     dpbDrive        DB ?
  103.     dpbUnit         DB ?
  104.     dpbSectorSize   DW ?
  105.     dpbClusterMask  DB ?
  106.     dpbClusterShift DB ?
  107.     dpbFirstFAT     DW ?
  108.     dpbFATCount     DB ?
  109.     dpbRootEntries  DW ?
  110.     dpbFirstSector  DW ?
  111.     dpbMaxCluster   DW ?
  112.     dpbFATSize      DW ?
  113.     dpbDirSector    DW ?
  114.     dpbDriverAddr   DD ?
  115.     dpbMedia        DB ?
  116.     dpbFirstAccess  DB ?
  117.     dpbNextDPB      DD ?
  118.     dpbNextFree     DW ?
  119.     dpbFreeCnt      DW ?
  120. DPB ENDS
  121.  
  122. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  123. ;
  124. ;  Used with: Interrupt 21h Function 11h
  125. ;             Interrupt 21h Function 12h
  126. ;
  127. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  128. EXTENDEDFCB STRUCT 1t
  129.     extSignature    DB 0FFh
  130.     extReserved1    DB 5 DUP(0)
  131.     extAttribute    DB ?
  132.     extDriveID      DB ?
  133.     extFileName     DB '????????'
  134.     extExtent       DB '???'
  135.     extCurBlockNo   DW ?
  136.     extRecSize      DW ?
  137.     extFileSize     DB 4 DUP(?)
  138.     extFileDate     DW ?
  139.     extFileTime     DW ?
  140.     extReserved2    DB 8 DUP(?)
  141.     extCurRecNo     DB ?
  142.     extRandomRecNo  DB 4 DUP(?)
  143. EXTENDEDFCB ENDS
  144.  
  145. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  146. ;
  147. ;  Used with: Interrupt 21h Function 11h
  148. ;             Interrupt 21h Function 12h
  149. ;
  150. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  151. EXTHEADER STRUCT 1t
  152.     ehSignature     DB 0FFh
  153.     ehReserved      DB 5 DUP(?)
  154.     ehSearchAttrs   DB ?
  155. EXTHEADER ENDS
  156.  
  157. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  158. ;
  159. ;  Used with: Interrupt 21h Function 0Fh
  160. ;             Interrupt 21h Function 10h
  161. ;             Interrupt 21h Function 11h
  162. ;             Interrupt 21h Function 12h
  163. ;             Interrupt 21h Function 13h
  164. ;             Interrupt 21h Function 14h
  165. ;             Interrupt 21h Function 15h
  166. ;             Interrupt 21h Function 16h
  167. ;             Interrupt 21h Function 17h
  168. ;             Interrupt 21h Function 1Bh
  169. ;             Interrupt 21h Function 1Ch and @ChkDrv MACRO
  170. ;             Interrupt 21h Function 21h
  171. ;             Interrupt 21h Function 22h
  172. ;             Interrupt 21h Function 23h
  173. ;             Interrupt 21h Function 24h
  174. ;             Interrupt 21h Function 27h
  175. ;             Interrupt 21h Function 28h
  176. ;             Interrupt 21h Function 29h
  177. ;
  178. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  179. FCB STRUCT 1t
  180.     fcbDriveID      DB ?
  181.     fcbFileName     DB '????????'
  182.     fcbExtent       DB '???'
  183.     fcbCurBlockNo   DW ?
  184.     fcbRecSize      DW ?
  185.     fcbFileSize     DB 4 DUP(?)
  186.     fcbFileDate     DW ?
  187.     fcbFileTime     DW ?
  188.     fcbReserved1    DB 8 DUP(?)
  189.     fcbCurRecNo     DB ?
  190.     fcbRandomRecNo  DB 4 DUP(?)
  191. FCB ENDS
  192.  
  193. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  194. ;
  195. ;  Used with: Interrupt 21h Function 4Eh and @GetFirst MACRO
  196. ;             Interrupt 21h Function 4Fh and @GetNext MACRO
  197. ;
  198. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  199. FILEINFO STRUCT 1t
  200.     fiReserved1     DB 21 DUP(?)
  201.     fiAttribute     DB ?
  202.     fiFileTime      DW ?
  203.     fiFileDate      DW ?
  204.     fiSize          DD ?
  205.     fiFileName      DB 13 DUP(?)
  206. FILEINFO ENDS
  207.  
  208. ; This structure declaration is included for compatability with earlier
  209. ; versions of DOS.INC.  The structure declaration above, which matches 
  210. ; the MS-DOS Programmer's Reference 5.0, should be used for new code.
  211. FILE_INFO STRUCT
  212.   pad           BYTE    21 DUP (?)      ; pad to 43 bytes
  213.   Attrib        BYTE    ?               ; file attribute
  214.   Time          WORD    ?               ; file time
  215.   Date          WORD    ?               ; file date
  216.   Len           DWORD   ?               ; file size
  217.   FName         BYTE    13 DUP (?)      ; file name
  218. FILE_INFO ENDS
  219.  
  220. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  221. ;
  222. ;  Used with: Interrupt 21h Function 440Dh Minor Code 42h
  223. ;             Interrupt 21h Function 440Dh Minor Code 62h
  224. ;
  225. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  226. FVBLOCK STRUCT 1t
  227.     fvSpecFunc      DB 0
  228.     fvHead          DW ?
  229.     fvCylinder      DW ?
  230. FVBLOCK ENDS
  231.  
  232. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  233. ;
  234. ;  Used with: Interrupt 21h Function 440Dh Minor Code 66h
  235. ;             Interrupt 21h Function 440Dh Minor Code 46h
  236. ;
  237. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  238. MID STRUCT 1t
  239.     midInfoLevel    DW 0
  240.     midSerialNum    DD ?
  241.     midVolLabel     DD 11 DUP(?)
  242.     midFileSysType  DB 8 DUP(?)
  243. MID ENDS
  244.  
  245. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  246. ;
  247. ;  Used with: Interrupt 21h Function 440Dh Minor Code 41h
  248. ;             Interrupt 21h Function 440Dh Minor Code 61h
  249. ;
  250. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  251. PARTENTRY STRUCT 1t
  252.     peBootable      DB ?
  253.     peBeginHead     DB ?
  254.     peBeginSector   DB ?
  255.     peBeginCylinder DB ?
  256.     peFileSystem    DB ?
  257.     peEndHead       DB ?
  258.     peEndSector     DB ?
  259.     peEndCylinder   DB ?
  260.     peStartSector   DD ?
  261.     peSectors       DD ?
  262. PARTENTRY ENDS
  263.  
  264. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  265. ;
  266. ;  Used with: Interrupt 21h Function 17h
  267. ;
  268. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  269. RENAMEFCB STRUCT 1t
  270.     renDriveID      DB ?
  271.     renOldName      DB '????????'
  272.     renOldExtent    DB '???'
  273.     renReserved1    DB 5 DUP(?)
  274.     renNewName      DB '????????'
  275.     renNewExtent    DB '???'
  276.     renReserved2    DB 9 DUP(?)
  277. RENAMEFCB ENDS
  278.  
  279. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  280. ;
  281. ;  Used with: Interrupt 21h Function 440Dh Minor Code 61h
  282. ;             Interrupt 21h Function 440Dh Minor Code 41h
  283. ;
  284. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  285. RWBLOCK STRUCT 1t
  286.     rwSpecFunc      DB 0
  287.     rwHead          DW ?
  288.     rwCylinder      DW ?
  289.     rwFirstSector   DW ?
  290.     rwSectors       DW ?
  291.     rwBuffer        DD ?
  292. RWBLOCK ENDS
  293.  
  294.  
  295. ; Internal
  296. __LdAdr MACRO reg:REQ, adr:REQ
  297.     IF (OPATTR (adr)) AND 00010000y
  298.         mov     reg, adr               ;; Register
  299.     ELSEIF (OPATTR (adr)) AND 00000100y
  300.         mov     reg, adr               ;; Constant
  301.     ELSEIF (TYPE (adr) EQ BYTE)  OR (TYPE (adr) EQ SBYTE)
  302.         mov    reg, OFFSET adr         ;; Bytes
  303.     ELSEIF (TYPE (adr) EQ NPVOID) OR (TYPE (adr) EQ WORD)
  304.         mov    reg, adr                ;; Near pointer
  305.     ELSEIF (TYPE (adr) EQ FPVOID) OR (TYPE (adr) EQ DWORD)
  306.         mov    reg, WORD PTR adr[0]    ;; Far pointer
  307.         mov    ds,  WORD PTR adr[2]
  308.     ELSE
  309.         .ERR <Illegal argument>
  310.     ENDIF
  311. ENDM
  312.  
  313.  
  314. ; Internal
  315. __LdSeg MACRO dest:REQ, src:REQ
  316.     IFIDNI <src>, <es>                 ;; Segment register
  317.         mov     ax, src
  318.         mov     dest, ax
  319.     ELSEIFIDNI <src>, <ss>
  320.         mov     ax, src
  321.         mov     dest, ax
  322.     ELSEIFIDNI <src>, <ds>
  323.         mov     ax, src
  324.         mov     dest, ax
  325.     ELSEIFIDNI <src>, <cs>
  326.         mov     ax, src
  327.         mov     dest, ax
  328.     ELSEIF (OPATTR (src)) AND 00000100y ;; Constant
  329.         mov     ax, src
  330.         mov     dest, ax
  331.     ELSE                                ;; Memory or general register
  332.         mov     dest, src
  333.     ENDIF
  334. ENDM
  335.  
  336. ; Internal
  337. __LdDub MACRO dub:REQ
  338.     IF ((OPATTR (dub)) AND 00000100y)
  339.         IF ((dub) LE 0FFFFh)
  340.              sub  cx, cx
  341.              mov  dx, dub
  342.         ELSE
  343.              sub  cx, HIGWORD dub
  344.              mov  dx, LOWWORD dub
  345.         ENDIF
  346.     ELSEIF   TYPE (dub) EQ 2
  347.         sub  cx, cx
  348.         mov  dx, dub
  349.     ELSEIF TYPE (dub) EQ 4
  350.         mov  cx, dub[2]
  351.         mov  dx, dub[0]
  352.     ELSEIF TYPE (dub) EQ 0
  353.         sub     cx, cx
  354.         mov     dx, dub
  355.     ELSE
  356.         .ERR
  357.         ECHO Illegal argument
  358.     ENDIF
  359. ENDM
  360.  
  361. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  362. ;
  363. ;  Syntax:    @GetChar [echo] [,[break] [,clearbuf]]
  364. ;
  365. ;  Summary:   Gets a keystroke from the keyboard
  366. ;
  367. ;  Arguments: <echo>         Nonzero to echo keystroke; default yes.
  368. ;                            Must be a constant.
  369. ;
  370. ;             <break>        Nonzero to accept CTRL+C; default yes. Must
  371. ;                            be a constant.
  372. ;
  373. ;             <clearbuf>     Nonzero to clear keyboard buffer; default
  374. ;                            no. Must be a constant.
  375. ;
  376. ;             NOTE: Arguments can be omitted to get defaults.
  377. ;
  378. ;  Returns:   ASCII code of key in AL
  379. ;
  380. ;  Modifies:  AX, else DL used if echo on and CTRL+C off
  381. ;
  382. ;  Uses:      Interrupt 21h Function 01h, 07h, 08h, 0Ch
  383. ;
  384. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  385. @GetChar MACRO ech:=<1>, cc:=<1>, clear:=<0>
  386.     LOCAL   funct, disp
  387.     disp    = 1
  388.     IF  ech
  389.         IF  cc
  390.             funct   = 01h       ;; Echo with break checking
  391.         ELSE
  392.             funct   = 07h       ;; Echo without break checking
  393.             disp    = 02h       ;; Need separate call to echo
  394.         ENDIF
  395.     ELSE
  396.         IF  cc
  397.             funct   = 08h       ;; No echo with break checking
  398.         ELSE
  399.             funct   = 07h       ;; No echo without break checking
  400.         ENDIF
  401.     ENDIF
  402.     IFE clear
  403.         mov     ah, funct       ;; Load function directly
  404.     ELSE
  405.         mov     ah, 0Ch         ;; If clear set, call function
  406.         mov     al, funct       ;;  indirectly with function 0Ch
  407.     ENDIF
  408.     int     21h                 ;; Call DOS
  409.     IF disp EQ 02h              ;; Separate call for echo without
  410.         mov     dl, al          ;;  break checking
  411.         mov     ah, disp
  412.         int     21h
  413.     ENDIF
  414. ENDM
  415.  
  416. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  417. ;
  418. ;  Syntax:    @GetStr buffer [,[terminator] [,[limit] [,segment]]]
  419. ;
  420. ;  Summary:   Gets a string from the keyboard
  421. ;
  422. ;  Arguments: <buffer>         Offset of buffer for string. Must be an
  423. ;                              offset address.
  424. ;
  425. ;                              Byte 1    Maximum length of string before
  426. ;                                        call.
  427. ;                              Byte 2    Actual length of string after
  428. ;                                        call.
  429. ;                              Byte 3+   Bytes of string.
  430. ;
  431. ;             <terminator>     Terminating byte: null (0) or $ (24h).
  432. ;                              May be a constant or register, but not memory.
  433. ;
  434. ;             <limit>          Maximum length of string. Must be a
  435. ;                              constant. If not given as an argument,
  436. ;                              must be in buffer before call.
  437. ;
  438. ;             <segment>        Segment of buffer; DS if not given.
  439. ;
  440. ;  Returns:   Pointer to string in SI, length of string in BX
  441. ;
  442. ;  Modifies:  AX, DX, BX, SI
  443. ;
  444. ;  Uses:      Interrupt 21h Function 0Ah
  445. ;
  446. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  447. @GetStr MACRO ofset:REQ, terminator, limit, segmnt
  448.     __LdAdr dx, <ofset>
  449.     IFNB    <segmnt>
  450.         __LdSeg ds, <segmnt>
  451.     ENDIF
  452.     mov     ah, 0Ah
  453.     mov     si, dx
  454.     IFNB    <limit>
  455.         mov     BYTE PTR [si], limit
  456.     ENDIF
  457.     int     21h
  458.     inc     si
  459.     mov     bl, [si]
  460.     sub     bh, bh
  461.     inc     si
  462.     IFNB    <terminator>
  463.         mov     BYTE PTR [bx+si], terminator
  464.     ENDIF
  465. ENDM
  466.  
  467. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  468. ;
  469. ;  Syntax:    @ShowChar char [,char]...
  470. ;
  471. ;  Summary:   Displays one or more characters to screen
  472. ;
  473. ;  Argument:  <char>     8-bit ASCII code
  474. ;
  475. ;  Returns:   No return value
  476. ;
  477. ;  Modifies:  AX, DL
  478. ;
  479. ;  Uses:      Interrupt 21h Function 02h
  480. ;
  481. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  482. @ShowChar MACRO chr:VARARG
  483.     mov     ah, 02h
  484.     FOR arg, <chr>
  485.         IFDIFI  <arg>, <dl>
  486.             mov     dl, arg
  487.         ENDIF
  488.         int     21h
  489.     ENDM
  490. ENDM
  491.  
  492. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  493. ;
  494. ;  Syntax:    @PrtChar char [,char]...
  495. ;
  496. ;  Summary:   Prints one or more characters to LPT1
  497. ;
  498. ;  Argument:  <char>     8-bit ASCII code
  499. ;
  500. ;  Returns:   No return value
  501. ;
  502. ;  Modifies:  AX, DL
  503. ;
  504. ;  Uses:      Interrupt 21h Function 05h
  505. ;
  506. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  507. @PrtChar MACRO chr:VARARG
  508.     mov     ah, 05h
  509.     FOR arg, <chr>
  510.         IFDIFI  <arg>, <dl>
  511.             mov     dl, arg
  512.         ENDIF
  513.         int     21h
  514.     ENDM
  515. ENDM
  516.  
  517. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  518. ;
  519. ;  Syntax:    @ShowStr address [,segment]
  520. ;
  521. ;  Summary:   Displays a $-terminated string
  522. ;
  523. ;  Arguments: <address>     Address of string terminated by "$" (24h).
  524. ;                           Must be an offset address.
  525. ;
  526. ;             <segment>     Segment of address string; DS if not given.
  527. ;
  528. ;  Returns:   No return value
  529. ;
  530. ;  Modifies:  AX, DX; DS if segment changed
  531. ;
  532. ;  Uses:      Interrupt 21h Function 09h
  533. ;
  534. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  535. @ShowStr MACRO ofset:REQ, segmnt
  536.     LOCAL  msg, sseg
  537.     IF @InStr( 1, ofset, <!"> ) EQ 1
  538.         sseg    TEXTEQU @CurSeg
  539.         .DATA
  540.         msg     BYTE    ofset, "$"
  541.     @CurSeg ENDS
  542.         sseg    SEGMENT
  543.         mov     dx, OFFSET msg
  544.     ELSE
  545.         __LdAdr dx, ofset
  546.         IFNB    <segmnt>
  547.             __LdSeg ds, <segmnt>
  548.         ENDIF
  549.     ENDIF
  550.     mov     ah, 9
  551.     int     21h
  552. ENDM
  553.  
  554. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  555. ;
  556. ;  Syntax:    @Read buffer, length [,[handle] [,segment]]
  557. ;
  558. ;  Summary:   Reads data from a file or device
  559. ;
  560. ;  Arguments: <buffer>      Offset of buffer where data will be stored.
  561. ;                           Must be an offset address.
  562. ;
  563. ;             <length>      Length of data in bytes.
  564. ;
  565. ;             <handle>      File or device handle; if none given,
  566. ;                           keyboard (handle 0) is assumed.
  567. ;
  568. ;             <segment>     Segment of address string; DS if not given.
  569. ;
  570. ;  Returns:   If carry: clear, bytes read in AX
  571. ;
  572. ;  Modifies:  AX, DX, BX, CX; DS if segment changed
  573. ;
  574. ;  Uses:      Interrupt 21h Function 3Fh
  575. ;
  576. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  577. @Read MACRO ofset:REQ, bytes:REQ, handle:=<0>, segmnt
  578.     IFDIF   <handle>, <0>
  579.         mov     bx, handle
  580.     ELSE
  581.         sub     bx, bx
  582.     ENDIF
  583.     mov     cx, bytes
  584.     __LdAdr dx, <ofset>
  585.     IFNB    <segmnt>
  586.         __LdSeg ds, <segmnt>
  587.     ENDIF
  588.     mov     ah, 3Fh
  589.     int     21h
  590. ENDM
  591.  
  592. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  593. ;
  594. ;  Syntax:    @Write buffer, length [,[handle] [,segment]]
  595. ;
  596. ;  Summary:   Writes data to a file or device
  597. ;
  598. ;  Arguments: <buffer>      Offset of buffer where data is stored. Must
  599. ;                           be an offset address.
  600. ;
  601. ;             <length>      Length of data in bytes.
  602. ;
  603. ;             <handle>      File or device handle; if none given, screen
  604. ;                           (handle 1) is assumed.
  605. ;
  606. ;             <segment>     Segment of address string; DS if not given.
  607. ;
  608. ;  Returns:   If carry: clear, bytes written in AX
  609. ;
  610. ;  Modifies:  AX, DX, BX, CX; DS if segment changed
  611. ;
  612. ;  Uses:      Interrupt 21h Function 40h
  613. ;
  614. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  615. @Write MACRO ofset:REQ, bytes:REQ, handle:=<1>, segmnt
  616.     mov     bx, handle
  617.     mov     cx, bytes
  618.     __LdAdr dx, <ofset>
  619.     IFNB    <segmnt>
  620.         __LdSeg ds, <segmnt>
  621.     ENDIF
  622.     mov     ah, 40h
  623.     int     21h
  624. ENDM
  625.  
  626. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  627. ;
  628. ;  Syntax:    @MakeFile path [,[attrib] [,[segment] [,kind]]]
  629. ;
  630. ;  Summary:   Creates a file
  631. ;
  632. ;  Arguments: <path>        ASCIIZ string of file. Must be an offset
  633. ;                           address.
  634. ;
  635. ;             <attrib>      File attribute; 0 is default if none given.
  636. ;
  637. ;             <segment>     Segment of address string; DS if not given.
  638. ;
  639. ;             <kind>        If none given, a file is created even if one
  640. ;                           already exists. Under DOS 3.x, "tmp" can be
  641. ;                           given to create a unique file or "new" to
  642. ;                           create a file only if one doesn't already
  643. ;                           exist.
  644. ;
  645. ;  Returns:   If carry: clear, file handle in AX
  646. ;
  647. ;  Modifies:  AX, DX, CX; DS if segment changed
  648. ;
  649. ;  Uses:      Interrupt 21h Function 3Ch, 5Ah, 5Bh
  650. ;
  651. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  652. @MakeFile MACRO path:REQ, atrib:=<0>, segmnt, kind
  653.     IFDIF   <atrib>, <0>
  654.         mov     cx, atrib
  655.     ELSE
  656.         sub     cx, cx
  657.     ENDIF
  658.     __LdAdr dx, <path>
  659.     IFNB    <segmnt>
  660.         __LdSeg ds, <segmnt>
  661.     ENDIF
  662.     IFIDNI  <kind>, <tmp>
  663.         mov     ah, 5Ah
  664.     ELSEIFIDNI <kind>, <new>
  665.         mov    ah, 5Bh
  666.     ELSE
  667.         mov    ah, 3Ch
  668.     ENDIF
  669.     int     21h
  670. ENDM
  671.  
  672. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  673. ;
  674. ;  Syntax:    @OpenFile path, access [,segment]
  675. ;
  676. ;  Summary:   Opens a file for input or output
  677. ;
  678. ;  Arguments: <path>        ASCIIZ string of file. Must be an offset
  679. ;                           address.
  680. ;
  681. ;             <access>      File access code. Must be a constant. The
  682. ;                           default value is 0 (normal read/write file).
  683. ;
  684. ;             <segment>     Segment of address string; DS if not given.
  685. ;
  686. ;  Returns:   If carry: set, error code in AX
  687. ;             If carry: clear, file handle in AX
  688. ;
  689. ;  Modifies:  AX, DX; DS if segment changed
  690. ;
  691. ;  Uses:      Interrupt 21h Function 3Dh
  692. ;
  693. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  694. @OpenFile MACRO path:REQ, access:=<0>, segmnt
  695.     __LdAdr dx, <path>
  696.     IFNB    <segmnt>
  697.         __LdSeg ds, <segmnt>
  698.     ENDIF
  699.     mov     ax, 3D00h + (access AND 0FFh)
  700.     int     21h
  701. ENDM
  702.  
  703. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  704. ;
  705. ;  Syntax:    @CloseFile handle
  706. ;
  707. ;  Summary:   Closes an open file handle
  708. ;
  709. ;  Argument:  <handle>     Previously opened file handle
  710. ;
  711. ;  Returns:   If carry: set, error code in AX
  712. ;
  713. ;  Modifies:  AX, BX
  714. ;
  715. ;  Uses:      Interrupt 21h Function 3Eh
  716. ;
  717. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  718. @CloseFile MACRO handle:REQ
  719.     mov     bx, handle
  720.     mov     ah, 3Eh
  721.     int     21h
  722. ENDM
  723.  
  724. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  725. ;
  726. ;  Syntax:    @DelFile path [,segment]
  727. ;
  728. ;  Summary:   Deletes a specified file
  729. ;
  730. ;  Arguments: <path>        Offset of ASCIIZ file specification. Must
  731. ;                           be an offset address.
  732. ;
  733. ;             <segment>     Segment of path; DS if none given.
  734. ;
  735. ;  Returns:   If carry: set, error code in AX
  736. ;
  737. ;  Modifies:  AX, DX; DS if segment changed
  738. ;
  739. ;  Uses:      Interrupt 21h Function 41h
  740. ;
  741. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  742. @DelFile MACRO path:REQ, segmnt
  743.     __LdAdr dx, <path>
  744.     IFNB    <segmnt>
  745.         __LdSeg ds, <segmnt>
  746.     ENDIF
  747.     mov     ah, 41h
  748.     int     21h
  749. ENDM
  750.  
  751. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  752. ;
  753. ;  Syntax:    @MoveFile old, new [,[segold] [,segnew]]
  754. ;
  755. ;  Summary:   Moves or renames a file by changing its path specification
  756. ;
  757. ;  Arguments: <old>        Offset of file specification to be renamed.
  758. ;                          Must be an offset address.
  759. ;
  760. ;             <new>        Offset of new file specification. Must be an
  761. ;                          offset address.
  762. ;
  763. ;             <segold>     Segment of old name; DS if none given.
  764. ;
  765. ;             <segnew>     Segment of new name; ES if none given.
  766. ;
  767. ;  Returns:   If carry: set, error code in AX
  768. ;
  769. ;  Modifies:  AX, DX, DI; DS, ES if corresponding segments changed
  770. ;
  771. ;  Uses:      Interrupt 21h Function 56h
  772. ;
  773. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  774. @MoveFile MACRO old:REQ, new:REQ, segold, segnew
  775.     __LdAdr dx, <old>
  776.     __LdAdr di, <new>
  777.     IFNB    <segold>
  778.         __LdSeg ds, <segold>
  779.     ENDIF
  780.     IFNB    <segnew>
  781.         __LdSeg es, <segnew>
  782.     ENDIF
  783.     mov     ah, 56h
  784.     int     21h
  785. ENDM
  786.  
  787. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  788. ;
  789. ;  Syntax:    @GetFirst path [,[attribute] [,segment]]
  790. ;             @GetNext
  791. ;
  792. ;  Summary:   Converts file specifications (optionally including wild
  793. ;             cards) into filenames. These macros are usually used with
  794. ;             @GetDTA and @SetDTA. Use @SetDTA to set the address where
  795. ;             the data for each file will be stored.
  796. ;
  797. ;  Arguments: <path>          Offset address of fully specified ASCIIZ
  798. ;                             file name; can have wild cards. Must be an
  799. ;                             offset address.
  800. ;
  801. ;             <attribute>     File attribute to search for; 0 for normal
  802. ;                             if none given.
  803. ;
  804. ;             <segment>       Segment of path; uses DS if none given.
  805. ;
  806. ;  Returns:   If carry: set, error code in AX
  807. ;
  808. ;  Modifies:  For @GetFirst, AX, CX, DX; DS if segment changed;
  809. ;             for @GetNext, AX only
  810. ;
  811. ;  Uses:      Interrupt 21h Function 4Eh
  812. ;
  813. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  814. @GetFirst MACRO path:REQ, atrib, segmnt
  815.     IFNB    <atrib>
  816.         mov     cx, atrib
  817.     ELSE
  818.         sub     cx, cx
  819.     ENDIF
  820.     __LdAdr dx, <path>
  821.     IFNB    <segmnt>
  822.         __LdSeg ds, <segmnt>
  823.     ENDIF
  824.     mov     ah, 4Eh
  825.     int     21h
  826. ENDM
  827.  
  828.  
  829. ; 4Fh
  830. @GetNext MACRO
  831.     mov     ah, 4Fh
  832.     int     21h
  833. ENDM
  834.  
  835. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  836. ;
  837. ;  Syntax:    @GetDTA
  838. ;
  839. ;             @SetDTA buffer [,segment]
  840. ;
  841. ;  Summary:   Gets or sets the Disk Transfer Address (DTA). These
  842. ;             macros are usually used to set the address for file
  843. ;             information data used by @GetFirst and @GetNext.
  844. ;
  845. ;  Arguments: <buffer>      Offset of new DTA buffer. Must be an offset
  846. ;                           address.
  847. ;
  848. ;             <segment>     Segment of new DTA buffer; DS if none given.
  849. ;
  850. ;  Returns:   @GetDTA: ES:BX points to DTA
  851. ;             @SetDTA: No return value
  852. ;
  853. ;  Modifies:  AX for both; ES, BX for @GetDTA; DS, DX for @SetDTA
  854. ;
  855. ;  Uses:      Interrupt 21h Function 2Fh
  856. ;
  857. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  858. @GetDTA MACRO
  859.     mov     ah, 2Fh
  860.     int     21h
  861. ENDM
  862.  
  863. ; 1Ah
  864. @SetDTA MACRO buffer:REQ, segmnt
  865.     __LdAdr dx, <buffer>
  866.     IFNB    <segmnt>
  867.         __LdSeg ds, <segmnt>
  868.     ENDIF
  869.     mov     ah, 1Ah
  870.     int     21h
  871. ENDM
  872.  
  873. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  874. ;
  875. ;  Syntax:    @GetFileSize handle
  876. ;
  877. ;  Summary:   Gets the file size by moving the file pointer to
  878. ;             end-of-file
  879. ;
  880. ;             NOTE: The file pointer is reset to zero. Thus this
  881. ;                   macro should not be called during operations that move
  882. ;                   the pointer.
  883. ;
  884. ;  Argument:  <handle>     Previously opened file handle.
  885. ;
  886. ;  Returns:   If carry: clear, file length in DX:AX
  887. ;
  888. ;  Modifies:  AX, BX, CX, DX
  889. ;
  890. ;  Uses:      Interrupt 21h Function 42h
  891. ;
  892. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  893. @GetFileSize MACRO handle:REQ
  894.     mov     bx, handle
  895.     sub     cx, cx
  896.     sub     dx, dx
  897.     mov     ax, 4202h
  898.     int     21h
  899.     push    dx
  900.     push    ax
  901.     sub     dx, dx
  902.     mov     ax, 4200h
  903.     int     21h
  904.     pop     ax
  905.     pop     dx
  906. ENDM
  907.  
  908. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  909. ;
  910. ;  Syntax:    @MovePtrAbs handle [,distance]
  911. ;
  912. ;             @MovePtrRel handle [,distance]
  913. ;
  914. ;  Summary:   Moves the file pointer in an open file. The pointer can be
  915. ;             moved to an absolute position, or relative to its current
  916. ;             position.
  917. ;
  918. ;  Arguments: <handle>       Previously opened file handle.
  919. ;
  920. ;             <distance>     Distance to move pointer (16-bit) constant
  921. ;                            or a 16- or 32-bit variable; or leave
  922. ;                            blank and set distance in CX:DX before
  923. ;                            macro call.
  924. ;
  925. ;  Returns:   If carry: clear, file pointer position in DX:AX
  926. ;
  927. ;  Modifies:  AX, BX, CX, DX
  928. ;
  929. ;  Uses:      Interrupt 21h Function 42h
  930. ;
  931. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  932. @MovePtrAbs MACRO handle:REQ, distance
  933.     IFNB    <distance>
  934.         __LdDub <distance>
  935.     ENDIF
  936.     mov     bx, handle
  937.     mov     ax, 4200h
  938.     int     21h
  939. ENDM
  940.  
  941. ; 42h
  942. @MovePtrRel MACRO handle:REQ, distance
  943.     IFNB    <distance>
  944.         __LdDub <distance>
  945.     ENDIF
  946.     mov     bx, handle
  947.     mov     ax, 4201h
  948.     int     21h
  949. ENDM
  950.  
  951. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  952. ;
  953. ;  Syntax:    @MkDir path [,segment]
  954. ;
  955. ;             @RmDir path [,segment]
  956. ;
  957. ;             @ChDir path [,segment]
  958. ;
  959. ;  Summary:   Creates, deletes, or changes to the specified directory
  960. ;
  961. ;  Arguments: <path>        Offset of ASCIIZ string containing
  962. ;                           directory. Must be offset address.
  963. ;
  964. ;             <segment>     Segment of path; DS if none given.
  965. ;
  966. ;  Returns:   If carry: set, error code in AX
  967. ;
  968. ;  Modifies:  AX, DX; DS if segment changed
  969. ;
  970. ;  Uses:      Interrupt 21h Function 39h
  971. ;
  972. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  973. @MkDir MACRO path:REQ, segmnt
  974.     __LdAdr dx, <path>
  975.     IFNB    <segmnt>
  976.         __LdSeg ds, <segmnt>
  977.     ENDIF
  978.     mov     ah, 39h
  979.     int     21h
  980. ENDM
  981.  
  982. ; 3Ah
  983. @RmDir MACRO path:REQ, segmnt
  984.     __LdAdr dx, <path>
  985.     IFNB    <segmnt>
  986.         __LdSeg ds, <segmnt>
  987.     ENDIF
  988.     mov     ah, 3Ah
  989.     int     21h
  990. ENDM
  991.  
  992. ; 3Bh
  993. @ChDir MACRO path:REQ, segmnt
  994.     __LdAdr dx, <path>
  995.     IFNB    <segmnt>
  996.         __LdSeg ds, <segmnt>
  997.     ENDIF
  998.     mov     ah, 3Bh
  999.     int     21h
  1000. ENDM
  1001.  
  1002. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1003. ;
  1004. ;  Syntax:    @GetDir buffer [,[drive] [,segment]]
  1005. ;
  1006. ;  Summary:   Returns the current directory of the specified drive
  1007. ;
  1008. ;  Arguments: <buffer>      Offset of buffer to receive ASCIIZ
  1009. ;                           directory. Must be an offset address.
  1010. ;
  1011. ;             <drive>       8-bit drive number (0 = current, 1 = A,
  1012. ;                           2 = B, ...; 0 if none given).
  1013. ;
  1014. ;             <segment>     Segment of path; DS if none given.
  1015. ;
  1016. ;  Returns:   If carry: set, error code in AX
  1017. ;
  1018. ;  Modifies:  AX, SI, DL; DS if segment changes
  1019. ;
  1020. ;  Uses:      Interrupt 21h Function 47h
  1021. ;
  1022. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1023. @GetDir MACRO buffer:REQ, drive, segmnt
  1024.     IFNB    <drive>
  1025.         mov     dl, drive
  1026.     ELSE
  1027.         sub     dl, dl
  1028.     ENDIF
  1029.     __LdAdr si, <buffer>
  1030.     IFNB    <segmnt>
  1031.         __LdSeg ds, <segmnt>
  1032.     ENDIF
  1033.     mov     ah, 47h
  1034.     int     21h
  1035. ENDM
  1036.  
  1037. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1038. ;
  1039. ;  Syntax:    @GetDrv
  1040. ;
  1041. ;             @SetDrv drive
  1042. ;
  1043. ;  Summary:   Gets or sets the current drive
  1044. ;
  1045. ;  Argument:  <drive>     8-bit drive number (0 = A, 1 = B, ...)
  1046. ;
  1047. ;  Returns:   For @GetDrv, drive number in AL (0 = A, 1 = B, ...);
  1048. ;             for @SetDrv, number of drives in AL
  1049. ;
  1050. ;  Modifies:  AX for both; DL for @SetDrv
  1051. ;
  1052. ;  Uses:      Interrupt 21h Function 19h
  1053. ;
  1054. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1055. @GetDrv MACRO
  1056.     mov     ah, 19h
  1057.     int     21h
  1058. ENDM
  1059.  
  1060. ; 0Eh
  1061. @SetDrv MACRO drive:REQ
  1062.     mov     dl, drive
  1063.     mov     ah, 0Eh
  1064.     int     21h
  1065. ENDM
  1066.  
  1067. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1068. ;
  1069. ;  Syntax:    @ChkDrv [drive]
  1070. ;
  1071. ;  Summary:   Gets various data about a disk
  1072. ;
  1073. ;  Argument:  <drive>     8-bit drive number (0 = current, A = 1,
  1074. ;                         B = 2, ...); if none given, current assumed
  1075. ;
  1076. ;  Returns:   AX     Sectors per cluster; -1 if drive invalid
  1077. ;             BX     Available clusters
  1078. ;             CX     Bytes per sector
  1079. ;             DX     Clusters per drive
  1080. ;
  1081. ;  Modifies:  AX, BX, CX, DX
  1082. ;
  1083. ;  Uses:      Interrupt 21h Function 1Ch
  1084. ;
  1085. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1086. @ChkDrv MACRO drive
  1087.     IFNB    <drive>
  1088.         mov     dl, drive
  1089.     ELSE
  1090.         sub     dl, dl
  1091.     ENDIF
  1092.     mov     ah, 1Ch
  1093.     int     21h
  1094. ENDM
  1095.  
  1096. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1097. ;
  1098. ;  Syntax:    @Exit [return]
  1099. ;
  1100. ;  Summary:   Exits to DOS with return code
  1101. ;
  1102. ;  Argument:  <return>     8-bit code to return to DOS; if none given,
  1103. ;                          AL is used. If given, must be a constant.
  1104. ;
  1105. ;  Returns:   No return value
  1106. ;
  1107. ;  Modifies:  AX
  1108. ;
  1109. ;  Uses:      Interrupt 21h Function 4Ch
  1110. ;
  1111. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1112. @Exit MACRO return
  1113.     IFB     <return>
  1114.         mov     ah, 4Ch
  1115.     ELSE
  1116.         mov     ax, 4C00h + (return AND 0FFh)
  1117.     ENDIF
  1118.     int     21h
  1119. ENDM
  1120.  
  1121. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1122. ;
  1123. ;  Syntax:    @TSR paragraphs [,return]
  1124. ;
  1125. ;  Summary:   Terminates a program, but leaves it resident in memory
  1126. ;
  1127. ;  Arguments: <paragraphs>     Memory in paragraphs (16 bytes) to
  1128. ;                              allocate for resident program.
  1129. ;             <return>         Code to return to DOS; if none, AL used.
  1130. ;                              Must be a constant.
  1131. ;
  1132. ;  Returns:   No return value
  1133. ;
  1134. ;  Modifies:  AX, DX
  1135. ;
  1136. ;  Uses:      Interrupt 21h Function 31h
  1137. ;
  1138. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1139. @TSR MACRO paragraphs:REQ, return
  1140.     mov     dx, paragraphs
  1141.     IFB     <return>
  1142.         mov     ah, 31h
  1143.     ELSE
  1144.         mov     ax, 3100h + (return AND 0FFh)
  1145.     ENDIF
  1146.     int     21h
  1147. ENDM
  1148.  
  1149. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1150. ;
  1151. ;  Syntax:    @FreeBlock [segment]
  1152. ;
  1153. ;  Summary:   Frees a block of memory
  1154. ;
  1155. ;  Argument:  <segment>     Starting address of memory to be freed; if
  1156. ;                           none given, ES address assumed
  1157. ;
  1158. ;  Returns:   If carry: set, error code in AX
  1159. ;
  1160. ;  Modifies:  AX; ES if segment given
  1161. ;
  1162. ;  Uses:      Interrupt 21h Function 49h
  1163. ;
  1164. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1165. @FreeBlock MACRO segmnt
  1166.     IFNB    <segmnt>
  1167.         __LdSeg es, <segmnt>
  1168.     ENDIF
  1169.     mov     ah, 49h
  1170.     int     21h
  1171. ENDM
  1172.  
  1173. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1174. ;
  1175. ;  Syntax:    @GetBlock paragraphs [, retry]
  1176. ;
  1177. ;  Summary:   Allocates a block of memory
  1178. ;
  1179. ;  Argument:  <paragraphs>     Paragraphs (16 bytes) of memory wanted
  1180. ;             <retry>          If nonzero, allocate largest block
  1181. ;                              available
  1182. ;
  1183. ;  Returns:   AX     If carry: clear, the segment of the allocated
  1184. ;                    memory. If carry: set, an error code
  1185. ;             BX     Paragraphs actually allocated. If <retry> is not
  1186. ;                    zero, it may be less than requested.
  1187. ;
  1188. ;  Modifies:  AX, BX
  1189. ;
  1190. ;  Uses:      Interrupt 21h Function 48h
  1191. ;
  1192. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1193. @GetBlock MACRO graphs:REQ, retry:=<0>
  1194.     LOCAL   tryit
  1195.     mov     bx, graphs
  1196.     tryit:  mov     ah, 48h
  1197.     int     21h
  1198.  
  1199.     IF      retry
  1200.     jc  tryit
  1201.     ENDIF
  1202. ENDM
  1203.  
  1204. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1205. ;
  1206. ;  Syntax:    @ModBlock paragraphs [,segment]
  1207. ;
  1208. ;  Summary:   Modifies an allocated block of memory
  1209. ;
  1210. ;  Arguments: <paragraphs>     Paragraphs (16 bytes) of memory wanted.
  1211. ;
  1212. ;             <segment>        Starting address of memory to be freed; if
  1213. ;                              none given, ES address assumed.
  1214. ;
  1215. ;  Returns:   If carry is set, the error code is returned in AX;
  1216. ;               otherwise, the ES register contains the segment address of
  1217. ;               allocated memory. If carry is clear, the BX register contains
  1218. ;               the number of paragraphs allocated.
  1219. ;
  1220. ;  Modifies:  AX, BX; ES if segment given
  1221. ;
  1222. ;  Uses:      Interrupt 21h Function 4Ah
  1223. ;
  1224. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1225. @ModBlock MACRO graphs:REQ, segmnt
  1226.     IFNB    <segmnt>
  1227.         __LdSeg es, <segmnt>
  1228.     ENDIF
  1229.     mov     bx, graphs
  1230.     mov     ah, 4Ah
  1231.     int     21h
  1232. ENDM
  1233.  
  1234. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1235. ;
  1236. ;  Syntax:    @GetDate
  1237. ;
  1238. ;  Summary:   Gets the system date
  1239. ;
  1240. ;  Arguments: None
  1241. ;
  1242. ;  Returns:   AL     Day of week (0 = Sunday, 1 = Monday, ...)
  1243. ;             CX     Year (1980-2099)
  1244. ;             DH     Month (1-12)
  1245. ;             DL     Day (1-31)
  1246. ;
  1247. ;  Modifies:  AX, CX, DX
  1248. ;
  1249. ;  Uses:      Interrupt 21h Function 2Ah
  1250. ;
  1251. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1252. @GetDate MACRO
  1253.     mov     ah, 2Ah
  1254.     int     21h
  1255. ENDM
  1256.  
  1257. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1258. ;
  1259. ;  Syntax:    @SetDate month, day, year
  1260. ;
  1261. ;  Summary:   Sets the system date
  1262. ;
  1263. ;  Arguments: <month>     8-bit month (1-12)
  1264. ;
  1265. ;             <day>       8-bit day (1-31)
  1266. ;
  1267. ;             <year>      16-bit year (1980-2099)
  1268. ;
  1269. ;  Returns:   AL     If date was valid 0, else -1
  1270. ;
  1271. ;  Modifies:  AX, CX, DX
  1272. ;
  1273. ;  Uses:      Interrupt 21h Function 2Bh
  1274. ;
  1275. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1276. @SetDate MACRO month:REQ, day:REQ, year:REQ
  1277.     mov     cx, year
  1278.     mov     dh, month
  1279.     mov     dl, day
  1280.     mov     ah, 2Bh
  1281.     int     21h
  1282. ENDM
  1283.  
  1284. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1285. ;
  1286. ;  Syntax:    @GetTime
  1287. ;
  1288. ;  Summary:   Gets the system time
  1289. ;
  1290. ;  Arguments: None
  1291. ;
  1292. ;  Returns:   CH     Hour (0-23)
  1293. ;             CL     Minute (0-59)
  1294. ;             DH     Second (0-59)
  1295. ;             DL     Hundredth (0-99)
  1296. ;
  1297. ;  Modifies:  AX, CX, DX
  1298. ;
  1299. ;  Uses:      Interrupt 21h Function 2Ch
  1300. ;
  1301. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1302. @GetTime MACRO
  1303.     mov     ah, 2Ch
  1304.     int     21h
  1305. ENDM
  1306.  
  1307. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1308. ;
  1309. ;  Syntax:    @SetTime hour,minute,second,hundredth
  1310. ;
  1311. ;  Summary:   Sets the system time
  1312. ;
  1313. ;  Arguments: <hour>          8-bit hours (0-23)
  1314. ;
  1315. ;             <minute>        8-bit minutes (0-59)
  1316. ;
  1317. ;             <second>        8-bit seconds (0-59)
  1318. ;
  1319. ;             <hundredth>     8-bit hundredth of seconds (0-99)
  1320. ;
  1321. ;  Returns:   AL     If time was valid 0, else -1
  1322. ;
  1323. ;  Modifies:  AX, CX, DX
  1324. ;
  1325. ;  Uses:      Interrupt 21h Function 2Dh
  1326. ;
  1327. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1328. @SetTime MACRO hour:REQ, minutes:REQ, seconds:REQ, hundredths:REQ
  1329.     mov     ch, hour
  1330.     mov     cl, minutes
  1331.     mov     dh, seconds
  1332.     mov     dl, hundredths
  1333.     mov     ah, 2Dh
  1334.     int     21h
  1335. ENDM
  1336.  
  1337. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1338. ;
  1339. ;  Syntax:    @GetVer
  1340. ;
  1341. ;  Summary:   Gets the DOS version
  1342. ;
  1343. ;  Arguments: None
  1344. ;
  1345. ;  Returns:   AL        Major version (0 for versions prior to 2.0)
  1346. ;             AH        Minor version
  1347. ;             BH        OEM serial number
  1348. ;             BL:CX     24-bit user number
  1349. ;
  1350. ;  Modifies:  AX, BX, CX
  1351. ;
  1352. ;  Uses:      Interrupt 21h Function 30h
  1353. ;
  1354. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1355. @GetVer MACRO
  1356.     mov     ah, 30h
  1357.     int     21h
  1358. ENDM
  1359.  
  1360. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1361. ;
  1362. ;  Syntax:    @GetInt interrupt
  1363. ;
  1364. ;             @SetInt interrupt, vector [,segment]
  1365. ;
  1366. ;  Summary:   Gets or sets the vector for a specified interrupt
  1367. ;             routine
  1368. ;
  1369. ;  Arguments: <interrupt>     8-bit interrupt number. Must be a
  1370. ;                             constant.
  1371. ;
  1372. ;             <vector>        Offset of interrupt routine.
  1373. ;
  1374. ;             <segment>       Segment of routine; if none given, DS
  1375. ;                             assumed for data; segment ignored for
  1376. ;                             code labels.
  1377. ;
  1378. ;  Returns:   For @GetInt, ES:BX points to interrupt routine;
  1379. ;             for @SetInt, no return value
  1380. ;
  1381. ;  Modifies:  AX for both; ES and BX for @GetInt; DS and DX for
  1382. ;             @SetInt
  1383. ;
  1384. ;  Uses:      Interrupt 21h Function 35h
  1385. ;
  1386. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1387. @GetInt MACRO   interrupt:REQ
  1388.     mov     ax, 3500h + (interrupt AND 0FFh)
  1389.     int     21h
  1390. ENDM
  1391.  
  1392. ; 25h
  1393. @SetInt MACRO interrupt:REQ, vector:REQ, segmnt
  1394.     IF  (TYPE (vector) EQ NPVOID) OR (TYPE (vector) EQ FPVOID)
  1395.         mov     dx, OFFSET vector
  1396.         mov     ax, SEG vector
  1397.         mov     ds, ax
  1398.     ELSE
  1399.         __LdAdr dx, <vector>
  1400.         IFNB    <segmnt>
  1401.             __LdSeg ds, <segmnt>
  1402.         ENDIF
  1403.     ENDIF
  1404.     mov     ax, 2500h + (interrupt AND 0FFh)
  1405.     int     21h
  1406. ENDM
  1407.